package hospital.user.api;

import hospital.model.user.UserInfo;
import hospital.result.Result;
import hospital.user.service.UserInfoService;
import hospital.utils.AuthContextHolder;
import hospital.vo.user.LoginVo;
import hospital.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * @author
 * @description:
 */
@Api("用户接口")
@RestController
@RequestMapping("/api/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * @Author yang
     * @Description //TODO 用户的登录验证
     * @Param [user]
     * @return
     **/
    @ApiOperation("登录验证")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo user){
        System.out.println(user.getCode() +" "+user.getPhone());
        Map<String,Object> map=userInfoService.login(user);
        return Result.ok(map);
    }

    /**
     * @Author yang
     * @Description //TODO 用户认证接口
     * @Param
     * @return
     **/
    @ApiOperation("用户认证接口")
    @PostMapping("auth/userAuth")
    public Result userAuth(@RequestBody UserAuthVo userAuth, HttpServletRequest request){
        System.out.println("保存的authVo："+userAuth.toString());
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuth);
        return Result.ok();
    }
    /**
     * @Author yang
     * @Description //TODO 获取用户id信息接口
     * @Param
     * @return
     **/
    @ApiOperation("获取用户id信息接口")
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        System.out.println("获取用户id信息接口");
        UserInfo userInfo = userInfoService.getById(AuthContextHolder.getUserId(request));
        return Result.ok(userInfo);
    }
}
